<?php
$nb_max="20"; // number of live per page

$page['live']=array();
$page['live_first_page']="";
$page['live_previous_page']="";
$page['live_last_page']="";
$page['live_next_page']="";
$page['L_message']="";
$plugin_idurl = 'live' ;

# suppression
if($right_user['delete_live'] AND isset($_GET['v2']) AND $_GET['v2']=="delete" AND isset($_GET['v3']) AND !empty($_GET['v3'])) 
{
 $var['id']=$_GET['v3'];
 $sql_sup=sql_replace($sql['live']['sup_live'],$var);
 $sgbd = sql_connect();

 if(sql_query($sql_sup) != false) { $page['L_message']=$lang['live']['form_live_sup_1']; }
 else { $page['L_message']=$lang['live']['form_live_sup_0']; }

 sql_close($sgbd);
}


# TRI
# $_GET['v1'] is a variable like : page_1_name_asc
if(isset($_GET['v1']) AND stristr($_GET['v1'],"page"))
{
 $v=explode("_",$_GET['v1']);
 $page_num=$v['1'];
 $tri=$v['2'];
 $ordre=$v['3'];
}
else
{
 $page_num=1; // number of the page
 $tri="name"; // tri par defaut
 $ordre="asc"; // ordre par defaut
}

# ORDRE (sens)
if($ordre=="desc") { $sens="desc"; $sens_inv="asc"; }
else { $sens="asc"; $sens_inv="desc"; }


/************************/
/* START CONDITIONS  */
/************************/
if(!isset($var['condition']) OR $var['condition']=="")
{
 $condition=array();

 # creation of conditions list
 $nb_condition=sizeof($condition);
 if($nb_condition==0) { $var['condition']=""; }
 elseif($nb_condition=="1") { $var['condition']="WHERE ".$condition['0']; }
 else { $var['condition']="WHERE ".implode(" AND ",$condition); }
}
/**********************/
/* END OF CONDITIONS    */
/**********************/


/**********************/
/* ORDER (tri) */
/**********************/
if(!isset($var['order']))
{
 switch($tri) {
  case "name" : $var['order']=" ORDER BY live_name ".$sens." "; break;
  default : $var['order']=" ORDER BY live_name ".$sens." ";
 }
}

$page['page']=array();
if(!isset($var['limit']))
{
 /* we get the number of live */
 $sql_nb=sql_replace($sql['live']['select_live_nb'],$var);
 $sgbd = sql_connect();
 $res_nb = sql_query($sql_nb);
 $ligne=sql_fetch_array($res_nb);
 $nb=$ligne['nb'];
 sql_free_result($res_nb);
 sql_close($sgbd);


 /***************/
 /* PAGINATION */
 /**************/
 # number of the current page
 $var['limit']="LIMIT ".($page_num-1)*$nb_max.",".$nb_max;
 $nb_page=ceil($nb/$nb_max);

 $url="index.php?r=".$plugin_idurl."&v1=page_";
 $end_url="_".$tri."_".$sens;

 $page['page']=generate_pagination($url, $nb_page,$page_num,$end_url);

 # previous page (except on the first one)
 if($page_num!=1)
 {
  $page['live_first_page']=convert_url($url."1".$end_url);
  $page['live_previous_page']=convert_url($url.($page_num - 1).$end_url);
 }
 # next page (except on the last one)
 if($page_num!=$nb_page)
 {
  $page['live_last_page']=convert_url($url.$nb_page.$end_url);
  $page['live_next_page']=convert_url($url.($page_num + 1).$end_url);
 }
 /******************/
 /* END PAGINATION */
 /******************/

}


$sql_live=sql_replace($sql['live']['select_live_condition'],$var);

// echo $sql_live ;

$sgbd = sql_connect();
$res_live = sql_query($sql_live);
$nb_ligne=sql_num_rows($res_live);

// echo '----------' . $nb_ligne ;

if(!$right_user['live_list']) {
	$page['L_message_club']=$lang['general']['acces_reserve_admin'];
}
elseif($nb_ligne=="0")
{
 $page['L_message']=$lang['live']['E_live_not_found'];
}
else
{
 $i="0";
 while($ligne = sql_fetch_array($res_live))
 {
    $page['live'][$i]['id']=$ligne['live_id'];
    $page['live'][$i]['name']=$ligne['live_name'];
    $page['live'][$i]['date']=$ligne['live_date'];
    $page['live'][$i]['description']=$ligne['live_description'];  
    $page['live'][$i]['mod']=$i%2;

    $page['live'][$i]['L_show_view']=$lang['live']['show_view'];
    $page['live'][$i]['live_view']=convert_url("index.php?r=".$plugin_idurl."&v1=view&v2=".$ligne['live_id']);

    if(isset($var['value_live']) AND $var['value_live']==$ligne['live_id']) { $page['live'][$i]['selected']="selected"; } else { $page['live'][$i]['selected']=""; }

    $page['live'][$i]['live_edit']="";
    $page['live'][$i]['live_delete']="";
    if($right_user['edit_live'])
    {
        $page['live'][$i]['live_edit']=convert_url("index.php?r=".$plugin_idurl."&v1=form_live&v2=".$ligne['live_id']); 
    }
    if($right_user['delete_live'])
    {
        $page['live'][$i]['live_delete']=convert_url("index.php?r=".$plugin_idurl."&v1=live_list&v2=delete&v3=".$ligne['live_id']);
    }
    $i++;
 }
}
sql_free_result($res_live);
sql_close($sgbd);

if($right_user['add_live'])
 {
  $page['live_add']=convert_url("index.php?r=".$plugin_idurl."&v1=form_live");
  $page['admin']="1";
 }
else
{
 $page['live_add']="";
 $page['admin']="";
}

# text
$page['link_live']=convert_url("index.php?r=".$plugin_idurl."&v1=live_list");
$page['live_tri_name']=convert_url("index.php?r=".$plugin_idurl."&v1=page_".$page_num."_name_".$sens_inv);
$page['live_tri_city']=convert_url("index.php?r=".$plugin_idurl."&v1=page_".$page_num."_city_".$sens_inv);
$page['live_tri_place']=convert_url("index.php?r=".$plugin_idurl."&v1=page_".$page_num."_place_".$sens_inv);


$page['L_order']=$lang['live']['order_by'];
$page['L_name']=$lang['live']['name'];
$page['L_date']=$lang['live']['date'];

$page['L_first_page']=$lang['live']['first_page'];
$page['L_previous_page']=$lang['live']['previous_page'];
$page['L_next_page']=$lang['live']['next_page'];
$page['L_last_page']=$lang['live']['last_page'];

$page['L_add']=$lang['live']['add_live'];
$page['L_title']=$lang['live']['live_list'];

# meta
$page['meta_title']=$lang['live']['live_list'];
$page['template']=$tpl['live']['live_list'];


?>